package com.xyht.sca_s.student_manage_system.modules.goods.controller;


import com.xyht.sca_s.student_manage_system.auth.util.JwtTokenUtil;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.sca_s.student_manage_system.modules.goods.entity.req.SmsGoodsAddReq;
import com.xyht.sca_s.student_manage_system.modules.goods.entity.req.SmsGoodsDeletedReq;
import com.xyht.sca_s.student_manage_system.modules.goods.entity.req.SmsGoodsUpdateReq;
import com.xyht.sca_s.student_manage_system.modules.goods.service.SmsGoodsService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 物品表(--迎新) 前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2024-01-17
 */
@RestController
@SecretBody
@RequestMapping("/goods/")
public class SmsGoodsController {

    @Resource
    private SmsGoodsService smsGoodsService;
    @Resource
    private JwtTokenUtil jwtTokenUtil;

    @ApiOperation("添加物品")
    @PostMapping("/add")
    public ResponseResult addGoods(HttpServletRequest request, @RequestBody SmsGoodsAddReq addReq){
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return smsGoodsService.addGoods(userId,addReq);
    }

    @ApiOperation("删除物品")
    @PostMapping("/deleted")
    public ResponseResult deletedGoods(@RequestBody SmsGoodsDeletedReq deletedReq){
        return smsGoodsService.deletedGoods(deletedReq);
    }

    @ApiOperation("修改物品信息")
    @PostMapping("/update")
    public ResponseResult updateGoods(@RequestBody SmsGoodsUpdateReq updateReq){
        return smsGoodsService.updateGoods(updateReq);
    }

    @ApiOperation("查看物品类别")
    @GetMapping("/list")
    public ResponseResult getGoodsList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                       @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                       @RequestParam(value = "name",required = false)String name,
                                       @RequestParam(value = "isOn",required = false)Integer isOn){
        return smsGoodsService.getGoodsList(pageNum,pageSize,name,isOn);
    }

}

